package com.tinem.platform.service.network.client.impl;

import com.tinem.platform.module.starter.jpa.entity.network.IpInfo;
import com.tinem.platform.module.starter.jpa.repository.network.IpInfoRepository;
import com.tinem.platform.service.network.client.IpInfoClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @author fzh
 * @version v1
 * @program: platform
 * @className Databash
 * @description 通过数据库获取ip信息
 * @site
 * @company
 * @create 2021-10-27 14:41
 */
@Slf4j
@Service
public class DatabaseIpInfoClient implements IpInfoClient {

    @Resource
    IpInfoRepository ipInfoRepository;

    @Override
    public IpInfo getLocationByIp(String ip) {
        Optional<IpInfo> ipInfoOptional = ipInfoRepository.findById(ip);
        if(ipInfoOptional.isPresent()){
            return ipInfoOptional.get();
        }
        return null;
    }
}
